<template>
  <div class="goods-comment">
    <div class="head">
      <div class="data">
        <p>
          <span>{{ list1.evaluateCount }}</span
          ><span>人购买</span>
        </p>
        <p>
          <span>{{ list1.praisePercent }}</span
          ><span>好评率</span>
        </p>
      </div>
      <div class="tags">
        <div class="dt">大家都在说：</div>
        <div class="dd">
          <a
            href="javascript:;"
            :class="idx != null ? '' : 'active'"
            @click="idx = null"
            >全部评价（1000）</a
          >
          <a
            href="javascript:;"
            :class="{ active: index == idx }"
            @click="idx = index"
            v-for="(item, index) in list1.tags"
            :key="index"
            >{{ item.title }}</a
          >
        </div>
      </div>
    </div>
    <div class="sort">
      <span>排序：</span>
      <a
        href="javascript:;"
        :class="{ active: actives == 1 }"
        @click="actives = 1"
        >默认</a
      >
      <a
        href="javascript:;"
        :class="{ active: actives == 2 }"
        @click="actives = 2"
        >最新</a
      >
      <a
        href="javascript:;"
        :class="{ active: actives == 3 }"
        @click="actives = 3"
        >最热</a
      >
    </div>
    <div class="list">
      <div class="item" v-for="(item, index) in list2.items" :key="index">
        <div class="user">
          <img
            src="http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/avatar_1.png"
            alt=""
          />
          <span>{{ item.member.nickname }}</span>
        </div>
        <div class="body">
          <div class="score">
            <i class="iconfont icon-wjx01"></i>
            <i class="iconfont icon-wjx01"></i>
            <i class="iconfont icon-wjx01"></i>
            <i class="iconfont icon-wjx01"></i>
            <i class="iconfont icon-wjx02"></i>
            <span
              class="attr"
              v-for="(it, idx) in item.orderInfo.specs"
              :key="idx"
              >{{ it.name }}:{{ it.nameValue }}</span
            >
          </div>
          <div class="text">
            {{ item.content }}
          </div>
          <div class="time">
            <span>{{ item.createTime }}</span>
            <span class="zan"
              ><i class="iconfont icon-dianzan"></i>{{ item.praiseCount }}</span
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import qs from "querystring";
export default {
  data() {
    return {
      list1: {},
      list2: {},
      query: {
        page: 2,
        pageSize: 20,
      },
      idx: null,
      actives: 1,
    };
  },
  async mounted() {
    // 商品评价分类数据
    let { data } = await axios.get(
      `https://mock.boxuegu.com/mock/1175/goods/${this.$route.query.id}/evaluate`
    );
    this.list1 = data.result;
    // 请求评论数据
    let { data: res } = await axios.get(
      `https://mock.boxuegu.com/mock/1175/goods/${
        this.$route.query.id
      }/evaluate/page?${qs.stringify(this.query)}`
    );
    this.list2 = res.result;
  },
};
</script>

<style lang="scss" scoped>
.goods-comment {
  .head {
    display: flex;
    padding: 30px 0;
    .data {
      width: 340px;
      display: flex;
      padding: 20px;
      p {
        flex: 1;
        text-align: center;
        span {
          display: block;
          &:first-child {
            font-size: 32px;
            color: red;
          }
          &:last-child {
            color: #999;
          }
        }
      }
    }
    .tags {
      flex: 1;
      display: flex;
      border-left: 1px solid #f5f5f5;
      .dt {
        font-weight: bold;
        width: 100px;
        text-align: right;
        line-height: 42px;
      }
      .dd {
        flex: 1;
        display: flex;
        flex-wrap: wrap;
        > a {
          width: 132px;
          height: 42px;
          margin-left: 20px;
          margin-bottom: 20px;
          border-radius: 4px;
          border: 1px solid #e4e4e4;
          background: #f5f5f5;
          color: #999;
          text-align: center;
          line-height: 40px;
          &:hover {
            border-color: #27bb9a;
            background: lighten(#27bb9a, 50%);
            color: #27bb9a;
          }
          &.active {
            border-color: #27bb9a;
            background: #27bb9a;
            color: #fff;
          }
        }
      }
    }
  }
  .sort {
    height: 60px;
    line-height: 60px;
    border-top: 1px solid #f5f5f5;
    border-bottom: 1px solid #f5f5f5;
    margin: 0 20px;
    color: #666;
    > span {
      margin-left: 20px;
    }
    > a {
      margin-left: 30px;
      &.active,
      &:hover {
        color: #27bb9a;
      }
    }
  }
}
.list {
  padding: 0 20px;
  .item {
    display: flex;
    padding: 25px 10px;
    border-bottom: 1px solid #f5f5f5;
    .user {
      width: 160px;
      img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        overflow: hidden;
      }
      span {
        padding-left: 10px;
        color: #666;
      }
    }
    .body {
      flex: 1;
      .score {
        line-height: 40px;
        .iconfont {
          color: #ff9240;
          padding-right: 3px;
        }
        .attr {
          padding-left: 10px;
          color: #666;
        }
      }
    }
    .text {
      color: #666;
      line-height: 24px;
    }
    .time {
      color: #999;
      display: flex;
      justify-content: space-between;
      margin-top: 5px;
    }
  }
}
</style>
